//
//  ImageEditView.m
//  Picture
//
//  Created by 孙玉琢 on 16/11/29.
//  Copyright © 2016年 孙玉琢. All rights reserved.
//

#import "ImageEditView.h"
// 屏幕高度
#define HEIGHT [UIScreen mainScreen].bounds.size.height
// 屏幕宽度
#define WIDTH [UIScreen mainScreen].bounds.size.width

@implementation ImageEditView

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        
        [self loadColors];
            
    }
    return self;
}
//颜色
-(void)loadColors{
    
    //set up colors
    self.colors = [NSArray array];
    self.colors = @[@"000000",@"FFFFFF",@"F54437",@"E91F63",@"9B29B0",@"663CB7",@"3F52B4",@"2198F2",@"03AAF4",@"01BCD4",@"019787",@"F6E1C3",@"8AC349",@"CCDC38",@"FDEB3A",@"FDC106",@"FE9900",@"FD5720",@"775545",@"9D9D9D",@"5F7C8A"];
    
    //configure swipe view
    _scrollView.alignment = SwipeViewAlignmentEdge;
    _scrollView.pagingEnabled = NO;
    _scrollView.wrapEnabled = NO;
    _scrollView.itemsPerPage = 3;
    _scrollView.truncateFinalPage = NO;
}
- (NSInteger)numberOfItemsInSwipeView:(SwipeView *)swipeView
{
    return [self.colors count];
}
- (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
    UILabel *label = (UILabel *)view;
    
    //create or reuse view
    if (view == nil)
    {
        label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, WIDTH/7, WIDTH/7)];
        
        label.textColor = [UIColor whiteColor];
        view = label;
    }
    
    label.backgroundColor = [UIColor hexStringToColor:[self.colors objectAtIndex:index]];
    //return view
    return view;
}
- (void)swipeView:(SwipeView *)swipeView didSelectItemAtIndex:(NSInteger)index
{
    _colorString = [self.colors objectAtIndex:index];
    [self.delegate changeColor:_colorString stickerViewID:self.stickerViewID];
}

- (IBAction)editStickerViewCenter:(UIButton *)sender {
    /*tag 3001 左移
          3002 右移
          3003 上移
          3004 下移
     */
    if (self.type == 1 || self.type == 2 || self.type == 3) {
        [self.delegate changeCenter:sender.tag stickerViewID:self.stickerViewID];
    }
}

- (IBAction)clickSlider:(UISlider *)sender {//缩放比例slider  angleValue
    
    if (self.type == 1 || self.type == 2 || self.type == 3) {
        [self.delegate changeSliderValue:sender.value stickerViewID:self.stickerViewID];
    }
}

//变比例
- (IBAction)changeScale:(UIButton *)sender {
    
    if (self.type == 1 || self.type == 2 || self.type == 3) {
        self.firstView.hidden = NO;
        self.secView.hidden = NO;
        self.angleView.hidden = YES;
        self.alphaView.hidden = YES;
        [self.delegate changeSelfHeight:sender.tag stickerViewID:self.stickerViewID imageEditType:self.type];//4001
    }
}

//变换角度
- (IBAction)changeAngle:(UIButton *)sender {
    if (self.type == 1 || self.type == 2 || self.type == 3) {
        self.firstView.hidden = YES;
        self.secView.hidden = YES;
        self.angleView.hidden = NO;
        self.alphaView.hidden = YES;
        [self.delegate changeSelfHeight:sender.tag stickerViewID:self.stickerViewID imageEditType:self.type];//4002
    }

}

//左转右转 button
- (IBAction)leftAndRightRotate:(UIButton *)sender {
    
    if (self.type == 1 || self.type == 2 || self.type == 3) {
        //7001 逆时针   7002 顺时针
        [self.delegate changeAngle:sender.tag stickerViewID:self.stickerViewID];
    }
    
}


//变换透明度
- (IBAction)changeAlpha:(UIButton *)sender {
    if (self.type == 1) {
        self.firstView.hidden = YES;
        self.secView.hidden = YES;
        self.angleView.hidden = YES;
        self.alphaView.hidden = NO;
        [self.delegate changeSelfHeight:sender.tag stickerViewID:self.stickerViewID imageEditType:self.type];//4003
    }else if (self.type == 2 || self.type == 3){
        self.firstView.hidden = YES;
        self.secView.hidden = YES;
        self.angleView.hidden = YES;
        self.alphaView.hidden = NO;
        self.scrollView.hidden = NO;
        [self.delegate changeSelfHeight:sender.tag stickerViewID:self.stickerViewID imageEditType:self.type];//4003

    }
}


- (IBAction)alphaSlider:(UISlider *)sender {//透明度比例slider  alphaValue
    if (self.type == 1 || self.type == 2 || self.type == 3) {
        [self.delegate changeAlpha:sender.value stickerViewID:self.stickerViewID];
    }
    
}

- (IBAction)clickForthBtn:(UIButton *)sender {
    
    if (self.type == 1 || self.type == 3) {
        [self.delegate changeSelfHeight:sender.tag stickerViewID:self.stickerViewID imageEditType:self.type];//4003
    }
    
}




- (IBAction)clickDelBtn:(UIButton *)sender {
    
    [self.delegate delStickerView:self.stickerViewID];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
@end
